package cn.wolfcode.shop.mapper;

import cn.wolfcode.shop.domain.SeckillGood;
import cn.wolfcode.shop.domain.SeckillOrder;
import cn.wolfcode.shop.vo.GoodVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Mapper 贴了该注解会被mybatis扫描接口类上的@Select注解上的sql
 */
@Mapper
public interface SeckillGoodMapper {
    @Select("select * from t_seckill_goods")
    List<SeckillGood> query();
    @Select("select * from t_seckill_goods where good_id = #{goodId}")
    List<SeckillGood> selectById(Long goodId);

    /**
     * 条件stock_count>0 作为执行减库存的前提条件,也就是乐观锁
     * @param goodId
     * @return
     */
    @Update("update t_seckill_goods set stock_count = stock_count-1 where good_id = #{goodId} AND stock_count > 0")
    int reduceStockCountByGoodId(Long goodId);
    @Select("select count(id) from t_seckill_goods where good_id = #{goodId}")
    int selectStockByGoodId(Long goodId);
}
